

//
//  YDCalendarView.m
//  PeiZiWangBei
//
//  Created by 巨彦新 on 2018/1/17.
//  Copyright © 2018年 LK-IOS. All rights reserved.
//

#import "YDCalendarView.h"
#import "YDNewsModel.h"



@interface YDCalendarView()

@property (nonatomic , weak) UIView *contentView;

/**
 星期几
 */
@property (nonatomic, strong)UILabel *weekLbl;

/**
 几号
 */
@property (nonatomic, strong)UILabel *dayLbl;


@end
@implementation YDCalendarView


-(void)setModel:(YDNewsModel *)model
{
    _model = model;
    
    
    self.weekLbl.text = model.week;
    self.dayLbl.text = model.day;
    
    if (model.isToday) {
        
        _weekLbl.textColor = [UIColor whiteColor];
        _weekLbl.backgroundColor = [UIColor blackColor];
        
        
        _dayLbl.textColor = [UIColor blackColor];
        _dayLbl.backgroundColor = [UIColor whiteColor];
        
    
        self.contentView.layer.borderWidth = 1;
        self.contentView.layer.borderColor = [UIColor blackColor].CGColor;
        
    }else{
        
        _weekLbl.textColor = [UIColor whiteColor];
        _weekLbl.backgroundColor = [UIColor colorWithHexString:battleshipGrey];
        
        
        _dayLbl.textColor = [UIColor colorWithHexString:battleshipGrey];
        _dayLbl.backgroundColor = [UIColor whiteColor];
        
        
        self.contentView.layer.borderWidth = 1;
        self.contentView.layer.borderColor = [UIColor colorWithHexString:battleshipGrey].CGColor;
        
    }
    
    
    
    
}


-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self contentView];
        [self weekLbl];
        [self dayLbl];
        
    }
    return self;
}

-(UIView *)contentView
{
    if (_contentView == nil) {
        UIView *contentView = [[UIView alloc] init];
        [self addSubview:contentView];
        contentView.backgroundColor = [UIColor whiteColor];
        [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.equalTo(@(rate375(32)));
            make.right.equalTo(self).offset(-rate375(10));
            if (isPhoneX) {
                make.top.equalTo(self).offset(rateX812(10));
            }else{
                make.top.equalTo(self).offset(rate750(10));
            }
        }];
        contentView.layer.cornerRadius = 4.0f;
        contentView.layer.masksToBounds = YES;
        contentView.layer.borderWidth = 1;
        contentView.layer.borderColor = [UIColor colorWithHexString:skyBlue].CGColor;
        _contentView = contentView;
    }
    return _contentView;
}
-(UILabel *)weekLbl
{
    if (_weekLbl == nil) {
        _weekLbl = [UILabel new];
        _weekLbl.text = @"星期三";
        _weekLbl.textColor = [UIColor whiteColor];
        _weekLbl.textAlignment = NSTextAlignmentCenter;
        _weekLbl.font = [UIFont systemFontOfSize:8];
        _weekLbl.backgroundColor = [UIColor colorWithHexString:skyBlue];
        [self.contentView addSubview:_weekLbl];
        [_weekLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self.contentView);
            make.height.equalTo(isPhoneX ? @(rateX812(12)) : @(rate750(12)));
        }];
    }
    return _weekLbl;
}

-(UILabel *)dayLbl
{
    if (_dayLbl == nil) {
        
        _dayLbl = [UILabel new];
        _dayLbl.text = @"28";
        _dayLbl.textColor = [UIColor colorWithHexString:skyBlue];
        _dayLbl.textAlignment = NSTextAlignmentCenter;
        _dayLbl.font = [UIFont systemFontOfSize:15];
        _dayLbl.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_dayLbl];
        [_dayLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView);
            make.top.equalTo(_weekLbl.mas_bottom);
            make.height.equalTo(isPhoneX ? @(rateX812(20)): @(rate750(20)));
        }];
        
    }
    return _dayLbl;
}
@end
